import { defineConfig } from 'umi';
import { resolve } from 'path';
// eslint-disable-next-line import/no-extraneous-dependencies
import px2viewport from 'postcss-px-to-viewport';

import routes from './routes';

export default defineConfig({
  nodeModulesTransform: {
    type: 'none',
  },
  // publicPath: process.env.NODE_ENV === 'production' ? '/' : 'http://172.17.5.204:8000/',
  dva: {
    immer: true,
    hmr: true,
  },
  ssr: {},
  exportStatic: {
    htmlSuffix: false,
    dynamicRoot: true,
  },
  hash: true,
  history: { type: 'browser' },
  fastRefresh: {},
  define: {
    TEST: 'test',
  },
  title: '观山人盘',
  chainWebpack(config: any) {
    config.module
      .rule('lint')
      .test(/\.ts(x)?$/)
      .pre()
      .include.add(resolve(__dirname, './src'))
      .end()
      .use('eslint')
      .loader('eslint-loader');
  },
  extraBabelPlugins: [
    [
      'import',
      { libraryName: 'antd-mobile', libraryDirectory: 'lib', style: true },
      'antd-mobile',
    ],
  ],
  extraPostCSSPlugins: [
    px2viewport({ viewportWidth: 750, unitPrecision: 5, minPixelValue: 1 }),
  ],
  //   publicPath: 'http://image.qiniu.gupengblog.cn/',
  routes,
});
